package JAVAFXManyWindow.pojo;

import JAVAFXManyWindow.init.IMGITEM;
import JAVAFXManyWindow.init.JXBrowserServerTcp;
import JAVAFXManyWindow.init.JavafxResourcesaddr;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Snail
 * @date 2019年3月26日 15:08:48
 * */
public class MainMe {
    public static List<Pane> root = new ArrayList<>();
    public static List<Stage> stage = new ArrayList<>();
    public static JavafxResourcesaddr javafxResourcesaddr = new JavafxResourcesaddr();
    public static JXBrowserServerTcp jxBrowserServerTcp = new JXBrowserServerTcp();
    public static int isopen=0;
    public static int isfile=0;
    public static List<IMGITEM> ImgDat=new ArrayList<>();
    /**
     * 获取窗体属性
     * */
    public static List<Stage> getStage() {
        return stage;
    }
    /**
     * 添加窗体
     * */
    public static void addStage() {
        MainMe.stage.add(new Stage());
        System.err.println("当前添加的窗口ID号为：" + MainMe.stage.size());
    }
    /**
     * 获取最大数
     * */
    public static int maxroot(){
        return MainMe.root.size();
    }
    /**
     * 获取最大数
     * */
    public static int maxStage(){
        return MainMe.stage.size();
    }
    /**
     * 关闭当前窗体
     * */
    public static void closeStage(int i,boolean flag,boolean flagpro){
        try {
            if(MainMe.stage.size()==0){
                System.err.println("当前窗口任务数：" + MainMe.stage.size() + "无需处理！");
            }else {
                MainMe.stage.get(i).close();
                if(flag==true){
                    MainMe.stage.get(i).setScene(null);
                }
                if(flagpro==true){
                    MainMe.root.remove(i);
                    MainMe.stage.remove(i);
                }
                System.err.println("当前窗口任务数：" + MainMe.stage.size() + "成功删除！");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 结速程序
     * */
    public static void stopStage(){
        try {
            MainMe.root.clear();
            MainMe.stage.clear();
            for (Stage s: MainMe.stage) {
                s.setScene(null);
            }
            System.err.println("当前窗口任务数：" + MainMe.stage.size() + "成功删除！终止线程");
            System.exit(0);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     *
     * 显示窗体
     * */
    public static void showStage(int i){
        try {
            MainMe.stage.get(i).show();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static int maxwindow(int stag){
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int screenWidth = (int) screenSize.getWidth();
        int screenHeight = (int) screenSize.getHeight();
        if(stag==0){
            return screenWidth;
        }else{
            return screenHeight;
        }
    }



}
